#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include <vector>
using namespace std;
class Solution {
public:
    int getmin(int x, int y, int z)
    {
        return min(min(x, y), z);
    }
    int GetUglyNumber_Solution(int index)
    {
        if (!index) return 0;

        vector<int> num;
        num.push_back(1);
        int count = 1;
        int i = 0, j = 0, k = 0;
        while (count < index)
        {
            num.push_back(getmin(num[i] * 2, num[j] * 3, num[k] * 5));
            count++;
            if (num[count - 1] == num[i] * 2)
                i++;
            if (num[count - 1] == num[j] * 3)
                j++;
            if (num[count - 1] == num[k] * 5)
                k++;
        }
        return num[count - 1];
    }
};